<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<style>
    body {
        height: 100%;
        width: 100%;
    }
</style>

<body style="background: red">
    <script>
        var sum = 100
        var t = setInterval(function () {  //循环执行定时器  每100毫秒执行一次
            // 补全代码   要求 red  green 交替
            var back = "#"
            for (var i = 0; i < 6; i++) {
                back += parseInt(Math.random() * 16).toString(16)
            }

            document.body.style.background = back
            if(sum ===2000){
                 clearInterval(t)   
            }
            sum += 100
        }, sum)

     
    </script>
</body>

</html>